# -*-coding:UTF-8-*-

from spider import Spider
import re
import time
import sched

print("间隔时间：",end="")
n = int(input())
s = Spider()

def task():
    result = s.request("http://blog.csdn.net/")
    pattern = "href=['\"](http://blog.csdn.net/[^'\"]*article/details[^'\"]*)['\"]"
    a = re.compile(pattern).findall(result)
    a = set(a)
    s.save(a)
    all = s.read()

    for i in range(0,len(all)):
        s.download(i,all[i])

while(1):
    print(u'程序启动时刻：', time.time())
    t = sched.scheduler(time.time, time.sleep)
    t.enter(1, 1, task)
    t.run()
    time.sleep(n)
